package com.github.fujianlian.klinechart;

import com.github.fujianlian.klinechart.entity.BuyAndSellingRecodeBean;
import com.github.fujianlian.klinechart.entity.EntityGriddingInfo;
import com.github.fujianlian.klinechart.entity.h.IKLine;
import com.github.fujianlian.klinechart.entity.NormType;
import com.github.fujianlian.klinechart.entity.h.IMA;
import com.github.fujianlian.klinechart.entity.h.ISKDJ;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * K线实体
 * Created by tifezh on 2016/5/16.
 */
public class KLineEntity implements IKLine {

    KLineEntity lstK;
    // K线数据
    Kline kline;

    // 条件单触发
    boolean tigger;
    // 预计盈利
    float predictWin;

    // 回撤止盈的基准价格
    float standardWinPrice;
    // 上涨百分比参数
    float winPersent;

    // 回撤百分比参数
    float retracPersent;

    // 5日平均涨幅
    float maGanD;
    // 当天涨幅与5日平均涨幅的比值
    float maGanDP;

    boolean maxP;
    float maxPrice;
    float lstMaxPrice;

    private float rsv;

    // 自定义成本
    public boolean customCost = false;
    public boolean customStopWinTag = false;
    // 阈值
    public float stopWinTag = 0.0f;

    // 止损止盈起始点
    public boolean stopPoint = false;


    float lstMinPrice;
    float minPrice;

    // 存储外部对象 通过类获取
    Map<Class, Object> objectMap = new HashMap<>();
    Map<String, Object> strogeMap = new HashMap<>();

    List<Float> stopWins = new ArrayList<>();
    List<Object> recodeBeanList = new ArrayList<>();

    LowBuyInfo lowBuyInfo;

    public KLineEntity() {
    }


    String Adj_Close;
    String Code;
    String name;

    public String Date;
    public float Open;
    public float High;
    public float Low;
    public float Close;
    public float Volume;

    IMA mMa;


    public float dea;

    public float dif;

    public float macd;

    public float k;

    public float d;

    public float j;


    public float r;

    public float rsi;

    public float up;

    public float mb;

    public float dn;

    public float cci;

    public float MA5Volume;

    public float MA10Volume;

    public float standardPrice = -1f;
    public float stepSize = -1f;

    float MCCi;
    float NCCi;

    List<EntityGriddingInfo> allGriddingInfos;
    /**
     * 当天价格 运行经过 的多级委托价格
     * （网格个值）
     */
    List<EntityGriddingInfo> griddingInfoList;

    /**
     * 当天价格预计的多级委托价格
     * （网格个值）
     */
    Map<Integer, EntityGriddingInfo[]> entrustGriddingMap;

    /**
     * 当日操作情况
     */
    Map<Integer, List<BuyAndSellingRecodeBean>> operateRecodeMap;

    float stop_profit_point;
    float stop_loss_point;
    // 允许自定义的成本价
    float mv_cost_price;
    // 特定成本价
    float cost_price;

    public float getCost_price() {
        return cost_price;
    }

    public void setCost_price(float cost_price) {
        this.cost_price = cost_price;
    }

    /**
     * 智能网格数据
     */
    List<Double> martGridValues;

    public float ENE_UPPER;
    public float ENE_LOWER;
    public float ENE;

    public double stopLost;
    public double stopWin;

    public IMA getMa() {
        return mMa;
    }

    public void setmMa(IMA mMa) {
        this.mMa = mMa;
    }

    public double getStopWin() {
        return stopWin;
    }

    public void setStopWin(double stopWin) {
        this.stopWin = stopWin;
    }

    public double getStopLost() {
        return stopLost;
    }

    public void setStopLost(double stopLost) {
        this.stopLost = stopLost;
    }

    public float getENE_LOWER() {
        return ENE_LOWER;
    }

    public void setENE_LOWER(float ENE_LOWER) {
        this.ENE_LOWER = ENE_LOWER;
    }

    public float getENE() {
        return ENE;
    }

    public void setENE(float ENE) {
        this.ENE = ENE;
    }

    public float getENE_UPPER() {
        return ENE_UPPER;
    }

    public void setENE_UPPER(float ENE_UPPER) {
        this.ENE_UPPER = ENE_UPPER;
    }


    public float getMA120Price() {
        return mMa.getMA120Price();
    }


    public float getMv_cost_price() {
        return mv_cost_price;
    }

    public void setMv_cost_price(float mv_cost_price) {
        this.mv_cost_price = mv_cost_price;
    }

    public float getStop_profit_point() {
        return stop_profit_point;
    }

    public void setStop_profit_point(float stop_profit_point) {
        this.stop_profit_point = stop_profit_point;
    }

    public float getStop_loss_point() {
        return stop_loss_point;
    }

    public void setStop_loss_point(float stop_loss_point) {
        this.stop_loss_point = stop_loss_point;
    }

    public List<EntityGriddingInfo> getAllGriddingInfos() {
        return allGriddingInfos;
    }

    public void setAllGriddingInfos(List<EntityGriddingInfo> allGriddingInfos) {
        this.allGriddingInfos = allGriddingInfos;
    }

    public Map<Integer, EntityGriddingInfo[]> getEntrustGriddingMap() {
        return entrustGriddingMap;
    }

    public void setEntrustGriddingMap(Map<Integer, EntityGriddingInfo[]> entrustGriddingMap) {
        this.entrustGriddingMap = entrustGriddingMap;
    }

    public Map<Integer, List<BuyAndSellingRecodeBean>> getOperateRecodeMap() {
        return operateRecodeMap;
    }

    @Override
    public List<Double> getSmartGridValues() {
        return martGridValues;
    }

    @Override
    public <T> T getEntity(String key, Class<T> tClass) {
        try {
            return (T) strogeMap.get(key);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public <T> T getEntity(Class<T> tClass) {
        try {
            return (T) objectMap.get(tClass);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    public void setOperateRecodeMap(Map<Integer, List<BuyAndSellingRecodeBean>> operateRecodeMap) {
        this.operateRecodeMap = operateRecodeMap;
    }

    // 触网有效性
    boolean relieveGridding;


    public List<EntityGriddingInfo> getGriddingInfoList() {
        return griddingInfoList;
    }


    public float getStepSize() {
        return stepSize;
    }


    public float getStandardPrice() {
        return standardPrice;
    }

    public void setStandardPrice(float standardPrice) {
        this.standardPrice = standardPrice;
    }

    public String getName() {
        return name;
    }

    public KLineEntity setName(String name) {
        this.name = name;
        return this;
    }


    public KLineEntity setAdj_Close(String adj_Close) {
        Adj_Close = adj_Close;
        return this;

    }

    public String getCode() {
        return Code;
    }

    public KLineEntity setCode(String code) {
        Code = code;
        return this;

    }

    public long dateTime = 0;

    public KLineEntity setDate(String date) {
        Date = date;
        try {
            dateTime = new SimpleDateFormat("yyyy-MM-dd").parse(date).getTime();
        } catch (ParseException e) {
//            e.printStackTrace();
        }
        return this;
    }

    public float getOpen() {
        return Open;
    }

    public KLineEntity setOpen(float open) {
        Open = open;
        return this;
    }

    public float getHigh() {
        return High;
    }

    public KLineEntity setHigh(float high) {
        High = high;
        return this;
    }

    public float getLow() {
        return Low;
    }

    public KLineEntity setLow(float low) {
        Low = low;
        return this;
    }

    public float getClose() {
        return Close;
    }

    public KLineEntity setClose(float close) {
        Close = close;
        return this;
    }

    public KLineEntity setVolume(float volume) {
        Volume = volume;
        return this;
    }

    ISKDJ skdj;

    public ISKDJ getSkdj() {
        return skdj;
    }

    public void setSkdj(ISKDJ skdj) {
        this.skdj = skdj;
    }


    public Float getSk() {
        return skdj == null ? 0f : skdj.getSk();
    }

    public Float getSd() {
        return skdj == null ? 0f : skdj.getSd();
    }


    public void setMacd(float macd) {
        this.macd = macd;
    }

    public void setD(float d) {
        this.d = d;
    }

    public void setJ(float j) {
        this.j = j;
    }

    public void setR(float r) {
        this.r = r;
    }

    public void setRsi(float rsi) {
        this.rsi = rsi;
    }

    public void setUp(float up) {
        this.up = up;
    }


    public Float getCCI() {
        return cci;
    }

    public void setCci(float cci) {
        this.cci = cci;
    }


    public int infoBeanId;


    public void setInfoBeanId(int infoBeanId) {
        this.infoBeanId = infoBeanId;
    }

    public void setRsv(Float rsv) {
        this.rsv = rsv;
    }


    public Float getRsv() {
        return rsv;
    }

    public Map<Class, Object> getObjectMap() {
        return objectMap;
    }

    public Map<String, Object> getStrogeMap() {
        return strogeMap;
    }

    public KLineEntity getLstK() {
        return lstK;
    }

    public void setLstK(KLineEntity lstK) {
        this.lstK = lstK;
    }

    public LowBuyInfo getLowBuyInfo() {
        return lowBuyInfo;
    }

    public void setLowBuyInfo(LowBuyInfo lowBuyInfo) {
        this.lowBuyInfo = lowBuyInfo;
    }

    public List<Object> getRecodeBeanList() {
        return recodeBeanList;
    }

    public void setRecodeBeanList(List<Object> recodeBeanList) {
        this.recodeBeanList = recodeBeanList;
    }

    public void setLstMinPrice(float lstMinPrice) {
        this.lstMinPrice = lstMinPrice;
    }

    public void setMinPrice(float minPrice) {
        this.minPrice = minPrice;
    }

    public Kline getKline() {
        return kline;
    }

    public void setKline(Kline kline) {
        this.kline = kline;
    }


    public boolean isTigger() {
        return tigger;
    }

    public void setTigger(boolean tigger) {
        this.tigger = tigger;
    }

    public float getPredictWin() {
        return predictWin;
    }

    public void setPredictWin(float predictWin) {
        this.predictWin = predictWin;
    }

    public float getStandardWinPrice() {
        return standardWinPrice;
    }

    public void setStandardWinPrice(float standardWinPrice) {
        this.standardWinPrice = standardWinPrice;
    }

    public float getWinPersent() {
        return winPersent;
    }

    public void setWinPersent(float winPersent) {
        this.winPersent = winPersent;
    }

    public float getRetracPersent() {
        return retracPersent;
    }

    public void setRetracPersent(float retracPersent) {
        this.retracPersent = retracPersent;
    }

    public float getLstMaxPrice() {
        return lstMaxPrice;
    }

    @Override
    public float getLstMinPrice() {
        return lstMinPrice;
    }

    @Override
    public float getMinPrice() {
        return minPrice;
    }


    public void setLstMaxPrice(float lstMaxPrice) {
        this.lstMaxPrice = lstMaxPrice;
    }


    public void setMaxP(boolean maxP) {
        this.maxP = maxP;
    }

    public float getMaxPrice() {
        return maxPrice;
    }

    public void setMaxPrice(float maxPrice) {
        this.maxPrice = maxPrice;
    }


    public void setMaGanDP(float maGanDP) {
        this.maGanDP = maGanDP;
    }

    public float getMaGanD() {
        return maGanD;
    }

    public void setMaGanD(float maGanD) {
        this.maGanD = maGanD;
    }

    public List<Float> getStopWins() {
        return stopWins;
    }


    public void setStopWinTag(float stopWinTag) {
        this.stopWinTag = stopWinTag;
    }

    public float getStopWinTag() {
        return stopWinTag;
    }

    public boolean isCustomCost() {
        return customCost;
    }

    public void setCustomCost(boolean customCost) {
        this.customCost = customCost;
    }

    public boolean isStopPoint() {
        return stopPoint;
    }

    public void setStopPoint(boolean stopPoint) {
        this.stopPoint = stopPoint;
    }

    public String getAdj_Close() {
        return Adj_Close;
    }


    public String getDate() {
        return Date;
    }



    @Override
    public float getDea() {
        return dea;
    }

    @Override
    public float getDif() {
        return dif;
    }

    @Override
    public float getMacd() {
        return macd;
    }

    @Override
    public float getK() {
        return k;
    }

    @Override
    public float getD() {
        return d;
    }

    @Override
    public float getJ() {
        return j;
    }

    @Override
    public float getR() {
        return r;
    }

    @Override
    public float getRsi() {
        return rsi;
    }

    @Override
    public float getUp() {
        return up;
    }

    @Override
    public float getMb() {
        return mb;
    }

    @Override
    public float getDn() {
        return dn;
    }

    @Override
    public float getVolume() {
        return Volume;
    }

    @Override
    public float getMA5Volume() {
        return MA5Volume;
    }

    @Override
    public float getMA10Volume() {
        return MA10Volume;
    }


    @Override
    public String toString() {
        return "KLineEntity{" +
                "rsv=" + rsv +
                ", Adj_Close='" + Adj_Close + '\'' +
                ", Code='" + Code + '\'' +
                ", name='" + name + '\'' +
                ", Date='" + Date + '\'' +
                ", Open=" + Open +
                ", High=" + High +
                ", Low=" + Low +
                ", Close=" + Close +
                ", Volume=" + Volume +
                ", mMa=" + mMa +
                ", dea=" + dea +
                ", dif=" + dif +
                ", macd=" + macd +
                ", k=" + k +
                ", d=" + d +
                ", j=" + j +
                ", skj=" + skdj +

                ", r=" + r +
                ", rsi=" + rsi +
                ", up=" + up +
                ", mb=" + mb +
                ", dn=" + dn +
                ", cci=" + cci +
                ", MA5Volume=" + MA5Volume +
                ", MA10Volume=" + MA10Volume +
                ", standardPrice=" + standardPrice +
                ", stepSize=" + stepSize +
                ", allGriddingInfos=" + allGriddingInfos +
                ", griddingInfoList=" + griddingInfoList +
                ", entrustGriddingMap=" + entrustGriddingMap +
                ", operateRecodeMap=" + operateRecodeMap +
                ", stop_profit_point=" + stop_profit_point +
                ", stop_loss_point=" + stop_loss_point +
                ", relieveGridding=" + relieveGridding +
                ", infoBeanId=" + infoBeanId +
                '}';
    }


    public void setMCCi(float MCCi) {
        this.MCCi = MCCi;
    }


    public void setNCCi(float NCCi) {
        this.NCCi = NCCi;
    }

    @Override
    public float getMCCI() {
        return MCCi;
    }

    @Override
    public float getNCCI() {
        return NCCi;
    }

    float speeI;

    public float getSpeeI() {
        return speeI;
    }

    public void setSpeeI(float speeI) {
        this.speeI = speeI;
    }


    @Override
    public NormType getType() {
        return NormType.main;
    }

    public static class LowBuyInfo {
        public KLineEntity start;
        public KLineEntity change;
        public KLineEntity end;
        public float stand;
        public float threshold;
        public float target;
        public boolean startPoint;

    }
}
